package com.jt.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jt.mapper.TeacherMapper;
import com.jt.pojo.Teacher;
import com.jt.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/teacher")
public class TeacherController {
    @Autowired
    private TeacherService service;
    @Autowired
    private TeacherMapper mapper;
    @GetMapping("selectAll")
    public List<Teacher> selectAll(Teacher teacher){
        QueryWrapper<Teacher> queryWrapper = new QueryWrapper<>(teacher);
        System.out.println(teacher.getTName());
        System.out.println(teacher.getTAge());
        List<Teacher> teachers = mapper.selectList(queryWrapper);
        return teachers;
        //return service.selectAll(teacher);
    }
    @PostMapping("addTeacher")
    public String addTeacher(@RequestBody Teacher teacher){
        service.addTeacher(teacher);
        return "添加成功！";
    }
    @PutMapping("/updateTeacher")
    public String updateTeacher(@RequestBody Teacher teacher){
        service.updateTeacher(teacher);
        return "修改成功！";
    }
    @GetMapping("/{tNo}")
    public String deleteTeacher(@PathVariable Integer tNo){
        mapper.deleteById(tNo);  //mybatis-plus可以直接在controller层完成基本的CRUD操作
       // service.deleteTeacher(tNo); //如果有其他业务还需要在service层完成
        return "删除成功！";
    }
}
